home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 12 / Mac Magazin and MacEasy Magazine CD - Issue 12.iso / Sharewarebibliothek / Anwendungen / Wissenschaft & Technik / Yorick / yorick11-nofpu folder / include / testg.i < prev    next >
Text File  |  1995-07-13  |  16KB  |  530 lines

  1. /*
  2.    TESTG.I
  3.    This file runs mesh plot movies. It should produce the same
  4.    results as the grbench C program.
  5.  
  6.    $Id: testg.i,v 1.1 1993/08/27 18:50:06 munro Exp $
  7.  */
  8. /*    Copyright (c) 1994.  The Regents of the University of California.
  9.                     All rights reserved.  */
  10.  
  11. func testg3
  12. /* DOCUMENT testg
  13.      runs a Yorick near-equivalent of Steve Langer's grbench graphics
  14.      timing benchmark. Tests both plf and pli.
  15.    SEE ALSO: lissajous, grtest
  16.  */
  17. {
  18.   /* set parameters */
  19.   NMID= 26;
  20.   N= 2*NMID-1;
  21.   xmax= ymax= 1.0;
  22.   alpha= 0.5;
  23.   dphi= 2.0*pi/8.3;
  24.   npass= 50;
  25.   ampy= cos(span(0.0, pi, N));
  26.  
  27.   /* set the maximum color index to use */
  28.   /* maxcolr= 192;
  29.      200 is the Yorick default -- grbench uses 192...
  30.      Could use pldefault, maxcolors=192 to be sure.   */
  31.  
  32.   /* create room for the x-coordinates of the mesh */
  33.   xmesh= array(double,N,N);
  34.   /* the y-coordinates of the mesh are fixed */
  35.   ymesh= span(0.0,ymax,N)(-:1:N,);
  36.  
  37.   /* be sure expose event is handled before starting into plots --
  38.      otherwise nothing will show */
  39.   if(!is_void(is_a_mac)) {
  40.     /* use existing window if on a Mac */
  41.   } else {
  42.     winkill, 0;
  43.     window, 0, wait=1, style="nobox.gs", dpi=100;
  44.   }
  45.  
  46.   if (is_void(dont_plot) || !dont_plot) {
  47.     write, "\nEach of the six tests will abort if one minute elapses,";
  48.     write, "so just be patient if you have a slow terminal.\n";
  49.     do_hollow, 0;
  50.     use_pli= 1;
  51.     do_filled, 0;
  52.     use_pli= 0;
  53.     do_filled, 0;
  54.     do_hollow, 1;
  55.     use_pli= 1;
  56.     do_filled, 1;
  57.     use_pli= 0;
  58.     do_filled, 1;
  59.   }
  60. }
  61.  
  62. func testg
  63. /* DOCUMENT testg
  64.      runs a Yorick near-equivalent of Steve Langer's grbench graphics
  65.      timing benchmark.
  66.    SEE ALSO: lissajous, grtest
  67.  */
  68. {
  69.   /* set parameters */
  70.   NMID= 26;
  71.   N= 2*NMID-1;
  72.   xmax= ymax= 1.0;
  73.   alpha= 0.5;
  74.   dphi= 2.0*pi/8.3;
  75.   npass= 50;
  76.   ampy= cos(span(0.0, pi, N));
  77.  
  78.   /* set the maximum color index to use */
  79.   /* maxcolr= 192;
  80.      200 is the Yorick default -- grbench uses 192...
  81.      Could use pldefault, maxcolors=192 to be sure.   */
  82.  
  83.   /* create room for the x-coordinates of the mesh */
  84.   xmesh= array(double,N,N);
  85.   /* the y-coordinates of the mesh are fixed */
  86.   ymesh= span(0.0,ymax,N)(-:1:N,);
  87.  
  88.   /* be sure expose event is handled before starting into plots --
  89.      otherwise nothing will show */
  90.   if(!is_void(is_a_mac)) {
  91.     /* use existing window if on a Mac */
  92.   } else {
  93.     winkill, 0;
  94.     window, 0, wait=1, style="nobox.gs", dpi=100;
  95.   }
  96.  
  97.   if (is_void(dont_plot) || !dont_plot) {
  98.     write, "\nEach of the four tests will abort if one minute elapses,";
  99.     write, "so just be patient if you have a slow terminal.\n";
  100.     do_hollow, 0;
  101.     do_filled, 0;
  102.     do_hollow, 1;
  103.     do_filled, 1;
  104.   }
  105. }
  106.  
  107. /* do a hollow mesh */
  108. func do_hollow(animation)
  109. {
  110.   if (animation) animate, 1;
  111.   else animate, 0;
  112.   fma;
  113.  
  114.   write, format="%d frames of hollow %d-by-%d mesh %s\n",\
  115.     npass, N, N, (animation? " animated" : " direct");
  116.   now= yorick= gist= array(0.0, 3);
  117.   timer, now;
  118.   now0= now(3);
  119.  
  120.   phi= -dphi;
  121.   for(np=1 ; np<=npass ; np++) {
  122.     phi= phi+dphi;
  123.     xdif= alpha*sin(phi);
  124.     xmj= 0.5*xmax*(1.0+xdif*ampy);
  125.  
  126.     for(j=1; j<=N; j++) {
  127.       xmesh(1:NMID,j)= span(0.0, xmj(j), NMID);
  128.       xmesh(NMID:N,j)= xmj(j)+span(0.0, xmax-xmj(j), NMID);
  129.     }
  130.  
  131.     timer, now, yorick;
  132.     plm, ymesh, xmesh;
  133.     fma;
  134.     timer, now, gist;
  135.     if (now(3)-now0 > 60.) {
  136.       write, "aborting after one minute, "+pr1(np)+" frames";
  137.       break;
  138.     }
  139.   }
  140.  
  141.   timer_print, "Yorick interpreter", yorick, "Gist graphics", gist,
  142.     "Yorick+Gist total", yorick+gist;
  143.   write, format="Frames per second (total/gist)=%.3f/%.3f\n",
  144.     np/(yorick(3)+gist(3)),np/gist(3);
  145.  
  146.   if (animation) animate, 0;
  147. }
  148.  
  149. /* do a filled mesh */
  150. func do_filled(animation)
  151. {
  152.   if (animation) animate, 1;
  153.   else animate, 0;
  154.   fma;
  155.  
  156.   write, format="%d frames of filled %d-by-%d mesh %s\n",
  157.     npass, N, N, (animation? " animated" : " direct");
  158.   now= yorick= gist= array(0.0, 3);
  159.   timer, now;
  160.   now0= now(3);
  161.  
  162.   dxmin= xmax*(1.0-alpha)/(2.0*NMID);
  163.   dxmax= xmax*(1.0+alpha)/(2.0*NMID);
  164.   phi= -dphi;
  165.   for(np=1 ; np<=npass ; np++) {
  166.     phi= phi+dphi;
  167.     xdif= alpha*sin(phi);
  168.     xmj= 0.5*xmax*(1.0+xdif*ampy);
  169.  
  170.     for(j=1; j<=N; j++) {
  171.       xmesh(1:NMID,j)= span(0.0, xmj(j), NMID);
  172.       xmesh(NMID:N,j)= xmj(j)+span(0.0, xmax-xmj(j), NMID);
  173.     }
  174.  
  175.     timer, now, yorick;
  176.     if (is_void(use_pli) || !use_pli)
  177.       plf, xmesh(dif,2:N),ymesh,xmesh, cmin=dxmin,cmax=dxmax;
  178.     else
  179.       pli, xmesh(dif,2:N), cmin=dxmin,cmax=dxmax;
  180.     fma;
  181.     timer, now, gist;
  182.     if (now(3)-now0 > 60.) {
  183.       write, "aborting after one minute, "+pr1(np)+" frames";
  184.       break;
  185.     }
  186.   }
  187.   timer, now, gist;
  188.  
  189.   timer_print, "Yorick interpreter", yorick, "Gist graphics", gist,
  190.     "Yorick+Gist total", yorick+gist;
  191.   write, format="Frames per second (total/gist)= %.3f/%.3f\n",
  192.     np/(yorick(3)+gist(3)),np/gist(3);
  193.  
  194.   if (animation) animate, 0;
  195. }
  196.  
  197. #if 0
  198. Results 75 MHz Pentium / Linux 1.1.87 / XF86_Mach64 server
  199. ($3000 from Gateway 2000 Jan/95 lets you animate nicely)
  200. 50 frames of hollow 51-by-51 mesh  direct
  201.                Timing Category     CPU sec  System sec    Wall sec
  202.             Yorick interpreter       0.800       0.000       0.800
  203.                  Gist graphics       1.150       0.130       2.760
  204.              Yorick+Gist total       1.950       0.130       3.560
  205. Frames per second (total/gist)=14.326/18.478
  206. 50 frames of filled 51-by-51 mesh  direct
  207.                Timing Category     CPU sec  System sec    Wall sec
  208.             Yorick interpreter       0.820       0.010       0.830
  209.                  Gist graphics       2.500       0.350      11.960
  210.              Yorick+Gist total       3.320       0.360      12.790
  211. Frames per second (total/gist)= 3.987/4.264
  212. 50 frames of hollow 51-by-51 mesh  animated
  213.                Timing Category     CPU sec  System sec    Wall sec
  214.             Yorick interpreter       0.870       0.010       0.920
  215.                  Gist graphics       1.130       0.140       3.480
  216.              Yorick+Gist total       2.000       0.150       4.400
  217. Frames per second (total/gist)=11.591/14.655
  218. 50 frames of filled 51-by-51 mesh  animated
  219.                Timing Category     CPU sec  System sec    Wall sec
  220.             Yorick interpreter       0.860       0.000       0.860
  221.                  Gist graphics       2.480       0.330       7.650
  222.              Yorick+Gist total       3.340       0.330       8.510
  223. Frames per second (total/gist)= 5.993/6.667
  224. #endif
  225.  
  226. func lissajous(animation)
  227. /* DOCUMENT lissajous
  228.      runs the Yorick equivalent of an old graphics performance test
  229.      used to compare PLAN, ALMA, and Basis with LTSS TMDS graphics.
  230.    SEE ALSO: testg, grtest
  231.  */
  232. {
  233.   /* Two figures with (x,y)= (cx,cy) + size*(cos(na*t), sin(nb*t+phase))
  234.      -- the centers describe semi-circular arcs of radius rc.  */
  235.   t= span(0, 2*pi, 400);
  236.   na1= 1;    nb1= 5;
  237.   na2= 2;    nb2= 7;
  238.   rc1= 40.;  rc2= 160.;
  239.   size= 40.;
  240.   phase= theta= 0.;
  241.  
  242.   /* number of frames in animation */
  243.   n= 50;
  244.   dtheta= pi/(n-1);
  245.   dphase= 2*pi/(n-1);
  246.  
  247.   window, 0, wait=1;
  248.   if (animation) animate, 1;
  249.   else animate, 0;
  250.   fma;
  251.  
  252.   split= now= array(0.0, 3);
  253.   timer, now;
  254.  
  255.   for (i=0 ; i<n ; i++) {
  256.     cost= cos(theta);
  257.     sint= sin(theta);
  258.     x= rc1*cost+size*cos(na1*t);  y= rc1*sint+size*sin(nb1*t+phase);
  259.     plg, y, x;
  260.     x= rc2*cost+size*cos(na2*t);  y= rc2*sint+size*sin(nb2*t+phase);
  261.     plg, y, x;
  262.     fma;
  263.     theta+= dtheta;
  264.     phase+= dphase;
  265.   }
  266.  
  267.   timer, now, split;
  268.   timer_print, "Lissajous test", split;
  269.   write,"Frames per wall clock second=",n/(split(3)+1.0e-6);
  270.  
  271.   if (animation) {
  272.     /* turn off animation and pop up final frame again */
  273.     animate, 0;
  274.     x= -rc1+size*cos(na1*t);  y= size*sin(nb1*t);
  275.     plg, y, x;
  276.     x= -rc2+size*cos(na2*t);  y= size*sin(nb2*t);
  277.     plg, y, x;
  278.   }
  279. }
  280.  
  281. func grtest(nstart)
  282. /* DOCUMENT grtest
  283.          or grtest, nstart
  284.      Perform a comprehensive test of Yorick's graphics package.
  285.      Pauses after each frame to let you check the result.  Each
  286.      picture attempts to describe itself (of course, if text
  287.      plotting is broken, this doesn't do any good).
  288.      With NSTART, start with test number NSTART.
  289.    SEE ALSO: testg, lissajous
  290.  */
  291. {
  292.   if (is_void(nstart)) nstart= 0;
  293.   write, "Yorick comprehensive graphics test.";
  294.   write, "Each frame will be described at the terminal.";
  295.   write, "Compare what you see with the description, then";
  296.   write, "hit <RETURN> to see the next test, or q <RETURN> to quit.\n";
  297.   pldefault, marks=1, width=0, type=1, style="work.gs", dpi=75;
  298.   winkill, 0;
  299.   if (nstart <= 1) {
  300.     write, "Test 1     Commands: window, 0, wait=1, dpi=100; plg, [0,1]";
  301.     window, 0, wait=1, dpi=100;
  302.     plg, [0,1];
  303.     write, "A large (100 dpi) window with line marked A from (1,0) to (2,1).";
  304.     if (strtok(rdline(prompt=""))(1)=="q") return;
  305.     winkill, 0;
  306.   }
  307.   window, 0, wait=1;
  308.   if (nstart <= 2) {
  309.     write, "Test 2     Commands: window, 0, wait=1; plg, [0,1]";
  310.     plg, [0,1];
  311.     write, "A small (75 dpi) window with line marked A from (1,0) to (2,1).";
  312.     if (strtok(rdline(prompt=""))(1)=="q") return;
  313.     unzoom;
  314.   } else {
  315.     plg, [0,1];
  316.   }
  317.   if (nstart <= 3) {
  318.     write, "Test 3     Commands: plg, [1,0]";
  319.     plg, [1,0];
  320.     write, "Added line marked B from (1,1) to (2,0) to previous plot.";
  321.     if (strtok(rdline(prompt=""))(1)=="q") return;
  322.     unzoom;
  323.   } else {
  324.     plg, [1,0];
  325.   }
  326.   if (nstart <= 4) {
  327.     write, "Test 4     Commands: logxy, 1, 0";
  328.     logxy, 1, 0;
  329.     write, "X axis now a log scale.";
  330.     if (strtok(rdline(prompt=""))(1)=="q") return;
  331.     unzoom;
  332.   }
  333.   if (nstart <= 5) {
  334.     write, "Test 5     Commands: logxy, 0, 0";
  335.     logxy, 0, 0;
  336.     write, "X axis back to linear scale.";
  337.     if (strtok(rdline(prompt=""))(1)=="q") return;
  338.     unzoom;
  339.   }
  340.   limits, 1.2, 1.8, 0.2, 0.8;
  341.   if (nstart <= 6) {
  342.     write, "Test 6     Commands: limits, 1.2, 1.8, 0.2, 0.8";
  343.     limits, 1.2, 1.8, 0.2, 0.8;
  344.     write, "Limits changed to 1.2<x<1.8, 0.2<y<0.8.";
  345.     if (strtok(rdline(prompt=""))(1)=="q") return;
  346.     unzoom;
  347.   }
  348.   range, 0.4, 0.6;
  349.   if (nstart <= 7) {
  350.     write, "Test 7     Commands: range, 0.4, 0.6";
  351.     write, "Limits changed to 1.2<x<1.8, 0.4<y<0.6.";
  352.     if (strtok(rdline(prompt=""))(1)=="q") return;
  353.     unzoom;
  354.   }
  355.   limits;
  356.   if (nstart <= 8) {
  357.     write, "Test 8     Commands: limits";
  358.     write, "Limits back to extreme values (1,0) to (2,1).";
  359.     if (strtok(rdline(prompt=""))(1)=="q") return;
  360.     unzoom;
  361.   }
  362.   fma;
  363.   x= span(0, 10*pi, 200);
  364.   plg, sin(x), x;
  365.   if (nstart <= 9) {
  366.     write, "Test 9     Commands: fma; plg, sin(x), x";
  367.     write, "Five cycles of a sine wave on a new frame.";
  368.     write, "Before you continue, try clicking with the mouse buttons:";
  369.     write, "Left button zooms in, right button zooms out, middle no zoom";
  370.     write, "In each case, the point where you press the mouse button will";
  371.     write, "be translated to the point where you release the mouse button.";
  372.     write, "To zoom one axis only, click over the tick marks on that axis.";
  373.     halt= strtok(rdline(prompt=""))(1)=="q";
  374.     unzoom;
  375.     if (halt) return;
  376.   }
  377.   pledit, marks=0, width=6, type="dash";
  378.   if (nstart <= 10) {
  379.     write, "Test 10     Commands: pledit, marks=0, width=6, type=\"dash\"";
  380.     write, "Marker A on sine curve disappears, curve becomes bold dashed.";
  381.     if (strtok(rdline(prompt=""))(1)=="q") return;
  382.     unzoom;
  383.   }
  384.   fma;
  385.   x= span(0, 2*pi, 200);
  386.   for (i=1 ; i<=6 ; i++) {
  387.     r= 0.5*i - (5-0.5*i)*cos(x);
  388.     plg, r*sin(x), r*cos(x), marks=0, color=-4-i;
  389.   }
  390.   if (nstart <= 11) {
  391.     write, "Test 11     Commands: plg, r*sin(x), r*cos(x), color=-4-i";
  392.     write, "A set of nested cardioids in the primary and secondary colors.";
  393.     if (strtok(rdline(prompt=""))(1)=="q") return;
  394.     unzoom;
  395.   }
  396.   pltitle, "Nested Cardioids";
  397.   if (nstart <= 12) {
  398.     write, "Test 12     Commands: pltitle, \"Colored nested cardioids\"; plq";
  399.     plq;
  400.     write, "Adds the title above the upper tick marks.";
  401.     write, "Also prints legends for the six curves at the terminal (plq).";
  402.     if (strtok(rdline(prompt=""))(1)=="q") return;
  403.     unzoom;
  404.   }
  405.   if (nstart <= 13) {
  406.     write, "Test 13     Commands: pledit, color=\"fg\", type=0, marker=i";
  407.     for (i=1 ; i<=5 ; i++) pledit,i, color="fg", type=0, marker=char(i);
  408.     pledit,i, color="fg", type=0, marker='A';
  409.     write, "Changes the colors to foreground, types to no lines.";
  410.     write, "Markers are point, plus, asterisk, O, X, A.";
  411.     if (strtok(rdline(prompt=""))(1)=="q") return;
  412.     unzoom;
  413.   }
  414.   if (nstart <= 14) {
  415.     write, "Test 14     Commands: pledit, marks=0, type=i";
  416.     for (i=1 ; i<=5 ; i++) pledit,i, marks=0, type=i;
  417.     pledit,i, color="fg", type=1, width=4;
  418.     write, "Changes line types to solid, dash, dot, dashdo, dashdotdot.";
  419.     write, "Outermost cardioid becomes a thick, solid line.";
  420.     if (strtok(rdline(prompt=""))(1)=="q") return;
  421.     unzoom;
  422.   }
  423.   fma;
  424.   limits;
  425.   x= span(-1, 1, 26)(,-:1:26);
  426.   y= transpose(x);
  427.   z= x+1i*y;
  428.   z= 5.*z/(5.+z*z);
  429.   xx= z.re;
  430.   yy= z.im;
  431.   if (nstart <= 15) {
  432.     write, "Test 15     Commands: plm, y, x";
  433.     write, "Quadrilateral mesh -- round with bites out of its sides.";
  434.     plm, yy, xx;
  435.     if (strtok(rdline(prompt=""))(1)=="q") return;
  436.     fma;
  437.     unzoom;
  438.   }
  439.   plmesh, yy, xx;
  440.   if (nstart <= 16) {
  441.     write, "Test 16     Commands: plv, v, u, y, x";
  442.     plv, x+.5, y-.5;
  443.     write, "Velocity vectors.  Try zooming and panning with mouse.";
  444.     if (strtok(rdline(prompt=""))(1)=="q") return;
  445.     fma;
  446.     unzoom;
  447.   }
  448.   if (nstart <= 17) {
  449.     write, "Test 17     Commands: plc, z, y,x; plm, y,x, boundary=1, type=2";
  450.     plc, abs(x+.5,y-.5), marks=1;
  451.     plm, boundary=1, type=2;
  452.     write, "Contours A-H, with mesh boundary dashed.";
  453.     if (strtok(rdline(prompt=""))(1)=="q") return;
  454.     fma;
  455.     unzoom;
  456.   }
  457.   if (nstart <= 18) {
  458.     write, "Test 18     Commands: plf, zncen(z), y,x;  plc, z, y,x";
  459.     z= abs(x+.5,y-.5);
  460.     plf, zncen(z);
  461.     plc, z, marks=0, type=2, color="bg", levs=[0.5, 1.0, 1.5];
  462.     write, "Filled mesh (color only) with three dashed contours overlayed.";
  463.     if (strtok(rdline(prompt=""))(1)=="q") return;
  464.     fma;
  465.     unzoom;
  466.   }
  467.   if (nstart <= 19) {
  468.     write, "Test 19     Commands: palette, \"<various>.gp\"";
  469.     write, "After each new palette is installed, hit <RETURN> for the next,";
  470.     write, "or q<RETURN> to begin test 20.  There are 6 palettes altogether.";
  471.     z= abs(x+.5,y-.5);
  472.     plf, zncen(z);
  473.     plc, z, marks=0, type=2, color="bg", levs=[0.5, 1.0, 1.5];
  474.     pal= ["heat.gp", "stern.gp", "rainbow.gp",
  475.       "gray.gp", "yarg.gp", "earth.gp"];
  476.     for (i=1 ; i<=6 ; i++) {
  477.       palette, pal(i);
  478.       write, format="Palette name: %s  ",pal(i);
  479.       if (strtok(rdline(prompt=""))(1)=="q") break;
  480.     }
  481.     if (i<6) palette, "earth.gp";
  482.     fma;
  483.     unzoom;
  484.   }
  485.   if (nstart <= 20) {
  486.     write, "Test 20     Commands: window, style=\"<various>.gs\"";
  487.     write, "After each new style is installed, hit <RETURN> for the next,";
  488.     write, "or q<RETURN> to begin test 21.  There are 5 styles altogether.";
  489.     pal= ["vg.gs", "boxed.gs", "vgbox.gs", "nobox.gs", "work.gs"];
  490.     for (i=1 ; i<=5 ; i++) {
  491.       window, style=pal(i);
  492.       plc, abs(x+.5,y-.5), marks=1;
  493.       plm, boundary=1, type=2;
  494.       write, format="Style name: %s  ",pal(i);
  495.       if (strtok(rdline(prompt=""))(1)=="q") break;
  496.     }
  497.     if (i<6) window, style="work.gs";
  498.     fma;
  499.     unzoom;
  500.   }
  501.   if (nstart <= 21) {
  502.     write, "Test 21     Commands: pli, image";
  503.     x= span(-6,6,200)(,-:1:200);
  504.     y= transpose(x);
  505.     r= abs(y,x);
  506.     theta= atan(y,x);
  507.     funky= cos(r)^2*cos(3*theta);
  508.     pli, funky;
  509.     write, "Cell array image (color only).  Three cycles in theta, r.";
  510.     if (strtok(rdline(prompt=""))(1)=="q") return;
  511.     fma;
  512.     unzoom;
  513.   }
  514.   if (nstart <= 22) {
  515.     write, "Test 22     Commands: pldj, x0, y0, x1, y1";
  516.     theta= span(0, 2*pi, 18)(zcen);
  517.     x= cos(theta)(,-:1:17);
  518.     y= sin(theta)(,-:1:17);
  519.     pldj, x, y, transpose(x), transpose(y);
  520.     pltitle, "Seventeen Pointed Stars"
  521.     limits, square= 1;
  522.     write, "All 17 pointed stars.";
  523.     halt= (strtok(rdline(prompt=""))(1)=="q");
  524.     limits, square= 0;
  525.     fma;
  526.     unzoom;
  527.     if (halt) return;
  528.   }
  529. }
  530.